
//列表数据

function barEVT(listData,ele){
	var max=0
	for(var i=0;i<listData.length;i++){
		if(max <= listData[i].value){
			max = listData[i].value;
		}
	}
	for(var i=0;i<listData.length;i++){
		//listData[i].per=(listData[i].value/max)*100+"%"
		var value = (listData[i].value/max)*100;
		if(value < 1){
			value = 1;
		}
		listData[i].per = value + "%";
	}
	$(ele).find(".barList").html("")
	for(var j=0;j<listData.length;j++){
		 $(ele).find(".barList").append("<li>"+
		   "<div style='color:#bed8e0'>"+(j+1)+"</div>"+
	       "<div style='color:#bed8e0'>"+listData[j].name+"</div>"+
	       "<div><p class='progressbar_1'>" +
	       "<span class='progress' style=width:"+listData[j].per+"></span>" +
	       	"</p></div>"+
	       "<div style='color:#bed8e0'>"+listData[j].value+"</div>"+
	       "</li>")
	}
}
var listData1=[
	{name:'浙江',value:260507,per:0},
	{name:'江苏',value:249883,per:0},
	{name:'广东',value:248923,per:0},
	{name:'北京',value:240918,per:0},
	{name:'河北',value:238839,per:0},
	{name:'福建',value:238066,per:0},
	{name:'辽宁',value:232009,per:0},
	{name:'湖北',value:231205,per:0},
	{name:'山东',value:230990,per:0},
	{name:'陕西',value:229935,per:0},
	{name:'湖南',value:229667,per:0},
	{name:'山西',value:229401,per:0},
	{name:'四川',value:228830,per:0},
	{name:'河南',value:227852,per:0},
	{name:'吉林',value:226710,per:0},
	{name:'天津',value:226590,per:0},
	{name:'重庆',value:225488,per:0},
	{name:'上海',value:223340,per:0},
	{name:'江西',value:222643,per:0},
	{name:'云南',value:219996,per:0},
	{name:'黑龙江',value:219286,per:0},
	{name:'广西',value:219119,per:0},
	{name:'甘肃',value:218437,per:0},
	{name:'内蒙古',value:218222,per:0},
	{name:'安徽',value:217726,per:0},
	{name:'贵州',value:216839,per:0},
	{name:'新疆',value:216567,per:0},
	{name:'海南',value:214735,per:0},
	{name:'青海',value:214567,per:0},
	{name:'宁夏',value:214327,per:0},
	{name:'西藏',value:214319,per:0}
]
var listData2=[
	{name:'北京',value:88,per:0},
	{name:'广东',value:66,per:0},
	{name:'上海',value:59,per:0},
	{name:'浙江',value:37,per:0},
	{name:'山东',value:37,per:0},
	{name:'江苏',value:34,per:0},
	{name:'河北',value:34,per:0},
	{name:'福建',value:28,per:0},
	{name:'天津',value:24,per:0},
	{name:'四川',value:23,per:0},
	{name:'湖北',value:22,per:0},
	{name:'辽宁',value:21,per:0},
	{name:'河南',value:21,per:0},
	{name:'湖南',value:20,per:0},
	{name:'陕西',value:18,per:0},
	{name:'重庆',value:18,per:0},
	{name:'广西',value:15,per:0},
	{name:'安徽',value:15,per:0},
	{name:'山西',value:14,per:0},
	{name:'吉林',value:14,per:0},
	{name:'江西',value:12,per:0},
	{name:'云南',value:12,per:0},
	{name:'黑龙江',value:12,per:0},
	{name:'贵州',value:12,per:0},
	{name:'甘肃',value:11,per:0},
	{name:'内蒙古',value:10,per:0},
	{name:'新疆',value:9,per:0},
	{name:'宁夏',value:9,per:0},
	{name:'西藏',value:8,per:0},
	{name:'青海',value:2,per:0},
	{name:'海南',value:0,per:0}
]
var listData3=[
	{name:'新疆',value:844360,per:0},
	{name:'青海',value:669194,per:0},
	{name:'宁夏',value:665650,per:0},
	{name:'北京',value:537390,per:0},
	{name:'山东',value:537358,per:0},
	{name:'湖北',value:537054,per:0},
	{name:'辽宁',value:536574,per:0},
	{name:'湖南',value:536568,per:0},
	{name:'重庆',value:536305,per:0},
	{name:'山西',value:536296,per:0},
	{name:'陕西',value:536273,per:0},
	{name:'安徽',value:536270,per:0},
	{name:'广西',value:536265,per:0},
	{name:'江西',value:536241,per:0},
	{name:'黑龙江',value:536241,per:0},
	{name:'云南',value:536208,per:0},
	{name:'贵州',value:536158,per:0},
	{name:'甘肃',value:536158,per:0},
	{name:'浙江',value:536084,per:0},
	{name:'江苏',value:536029,per:0},
	{name:'河北',value:536024,per:0},
	{name:'四川',value:535961,per:0},
	{name:'河南',value:535961,per:0},
	{name:'内蒙古',value:535897,per:0},
	{name:'福建',value:535756,per:0},
	{name:'吉林',value:534248,per:0},
	{name:'西藏',value:532553,per:0},
	{name:'天津',value:463771,per:0},
	{name:'上海',value:463315,per:0},
	{name:'广东',value:463275,per:0},
	{name:'海南',value:0,per:0}
]
var listData4=[
	{name:'网宿科技',value:6756130,per:0},
	{name:'蓝汛科技',value:77288,per:0},
	{name:'阿里云',value:71334,per:0},
	{name:'中国电信',value:45036,per:0},
	{name:'广东唯一',value:42828,per:0},
	{name:'北京快网',value:10628,per:0},
	{name:'腾讯云',value:6274,per:0},
	{name:'帝联科技',value:5433,per:0},
	{name:'北京京东叁佰陆拾度',value:3927,per:0},
	{name:'白山云',value:3435,per:0}
]
var listData5=[
	{name:'蓝汛科技',value:893915,per:0},
	{name:'阿里云',value:404262,per:0},
	{name:'网宿科技',value:317658,per:0},
	{name:'腾讯云',value:148796,per:0},
	{name:'广东唯一',value:85892,per:0},
	{name:'帝联科技',value:32297,per:0},
	{name:'北京快网',value:13784,per:0},
	{name:'百度网讯',value:1499,per:0},
	{name:'白山云',value:892,per:0},
	{name:'同兴万点',value:745,per:0}
]
barEVT(listData1,".proCDN") 
barEVT(listData4,".comCDN")

$(".proCDN .tab_classify li").click(function(){
	$(this).addClass("active").siblings().removeClass("active")
	 var n=$(this).index()
	 if(n==0){
		 barEVT(listData1,".proCDN") 
	 }else if(n==1){
		 barEVT(listData2,".proCDN") 
	 }else if(n==2){
		 barEVT(listData3,".proCDN") 
	 }
})
$(".comCDN .tab_classify li").click(function(){
	$(this).addClass("active").siblings().removeClass("active")
	 var n=$(this).index()
	 if(n==0){
		 barEVT(listData4,".comCDN") 
	 }else if(n==1){
		 barEVT(listData5,".comCDN") 
	 }
})


var geoCoordMap={}
var mapFeatures = echarts.getMap('china').geoJson.features;
mapFeatures.forEach(function(v) {
    // 地区名称
    var name = v.properties.name;
    // 地区经纬度
    geoCoordMap[name] = v.properties.cp;
});
var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
        var geoCoord = geoCoordMap[data[i].name];
        if (geoCoord) {
            res.push({
                name: data[i].name,
                value: geoCoord.concat(data[i].value)
            });
        }
    }
    return res;
};
var mapData = [
	{name:'北京',value:88},
	{name:'天津',value:24},
	{name:'河北',value:34},
	{name:'山西',value:14},
	{name:'内蒙古',value:10},
	{name:'辽宁',value:21},
	{name:'吉林',value:14},
	{name:'黑龙江',value:12},
	{name:'上海',value:59},
	{name:'江苏',value:34},
	{name:'浙江',value:37},
	{name:'安徽',value:15},
	{name:'福建',value:28},
	{name:'江西',value:12},
	{name:'山东',value:37},
	{name:'河南',value:21},
	{name:'湖北',value:22},
	{name:'湖南',value:20},
	{name:'广东',value:66},
	{name:'广西',value:15},
	{name:'海南',value:0 },
	{name:'重庆',value:18},
	{name:'四川',value:23},
	{name:'贵州',value:12},
	{name:'云南',value:12},
	{name:'西藏',value:8 },
	{name:'陕西',value:18},
	{name:'甘肃',value:11},
	{name:'青海',value:2 },
	{name:'宁夏',value:9 },
	{name:'新疆',value:9 },
];
var mapChart = echarts.init(document.getElementById('ec_map_nd'))
mapChart.setOption(getOptionMap(mapData,'企业'))

function getOptionMap(data,type){
	var max=0;
	for(var i=0;i<data.length;i++){
		if(max<data[i].value||max==data[i].value){
			max=data[i].value
		}
	}
	console.log(max)
	var optionMap = {
		tooltip: {
			trigger: 'item',
			formatter: function(param) {
				var province = param.name;
				//					if(province !='香港' && province !='澳门' && province !='台湾'){
				return '<div>' + param.name + '</div>' +
					'<div>' + type + '数量：' + param.data.value[2] + '</div>';
			}
			//				}
		},
		geo: {
			show: true,
			zoom: 1.2,
			roam: false,
			map: 'china',
			itemStyle: {
				normal: {
					show: false,
					borderColor: '#285ac6',
					borderWidth: 1,
					areaColor: '#123082',
					shadowBlur: 3,
					shadowColor: '#081435',
					shadowOffsetX: -4,
					shadowOffsetY: 8
				},
				emphasis: {
					areaColor: '#fce24f',
					borderColor: '#fce24f'
				}
			}
		},
		series: [{
			type: 'map',
			zoom: 1.2,
			mapType: 'china',
			//		geoIndex: 0,
			roam: false,
			label: {
				normal: {
					show: false,
					textStyle: {
						color: '#fff'
					}
				},
				emphasis: {
					show: true,
					textStyle: {
						color: '#fff'
					}
				}
			},
			itemStyle: {
				normal: {
					show: false,
					borderColor: '#3770ea',
					borderWidth: 1,
					areaColor: '#0f2d87'
				},
				emphasis: {
					areaColor: '#2a56bd',
					borderColor: '#2a56bd',
					//				opacity: 0.8,
				}
			},
			data: convertData(data)
		}, {
			name: 'Top 5',
			type: 'effectScatter',
			zlevel: 1,
			coordinateSystem: 'geo',
			symbolSize: function(val) {
				return val[2] / max * 20 + 5
			},
			showEffectOn: 'render',
			rippleEffect: {
				brushType: 'stroke'
			},
			hoverAnimation: true,
			label: {
				normal: {
					//            formatter: '{b}',
					position: 'right',
					show: false
				}
			},
			itemStyle: {
				normal: {
					color: '#f4e925',
					shadowBlur: 10,
					shadowColor: '#333'
				}
			},
			//    data: convertData(mapData)
			data: convertData(data.sort(function(a, b) {
				return b.value - a.value
			}).slice(0, 5))
		}, {
			name: 'Top 5',
			type: 'scatter',
			zlevel: 1,
			coordinateSystem: 'geo',
			symbolSize: function(val) {
				//        return val*4+8;
				return val[2] / max * 10 + 5
			},
			showEffectOn: 'render',
			rippleEffect: {
				brushType: 'stroke'
			},
			hoverAnimation: true,
			label: {
				normal: {
					//            formatter: '{b}',
					position: 'right',
					show: false
				}
			},
			itemStyle: {
				normal: {
					color: '#f4e925',
					shadowBlur: 10,
					shadowColor: '#333'
				}
			},
			//    data: convertData(mapData)
			data: convertData(data.sort(function(a, b) {
				return b.value - a.value;
			}).slice(5))
		}]
	};
	return optionMap;
}
$(".mapChange").change(function(){
    var n = $(this).val();
    var option = null;
    var mapData = null;
    if(n =="企业"){
    	mapData = [
    		{name:'北京',value:88},
    		{name:'天津',value:24},
    		{name:'河北',value:34},
    		{name:'山西',value:14},
    		{name:'内蒙古',value:10},
    		{name:'辽宁',value:21},
    		{name:'吉林',value:14},
    		{name:'黑龙江',value:12},
    		{name:'上海',value:59},
    		{name:'江苏',value:34},
    		{name:'浙江',value:37},
    		{name:'安徽',value:15},
    		{name:'福建',value:28},
    		{name:'江西',value:12},
    		{name:'山东',value:37},
    		{name:'河南',value:21},
    		{name:'湖北',value:22},
    		{name:'湖南',value:20},
    		{name:'广东',value:66},
    		{name:'广西',value:15},
    		{name:'海南',value:14 },
    		{name:'重庆',value:18},
    		{name:'四川',value:23},
    		{name:'贵州',value:12},
    		{name:'云南',value:12},
    		{name:'西藏',value:8 },
    		{name:'陕西',value:18},
    		{name:'甘肃',value:11},
    		{name:'青海',value:2 },
    		{name:'宁夏',value:9 },
    		{name:'新疆',value:9 },
    	];
    	option = getOptionMap(mapData,n);
    }else if(n =="域名"){
    	mapData = [
    		{name:'北京',value:537390},
    		{name:'天津',value:463771},
    		{name:'河北',value:536024},
    		{name:'山西',value:536296},
    		{name:'内蒙古',value:535897},
    		{name:'辽宁',value:536574},
    		{name:'吉林',value:534248},
    		{name:'黑龙江',value:536241},
    		{name:'上海',value:463315},
    		{name:'江苏',value:536029},
    		{name:'浙江',value:536084},
    		{name:'安徽',value:536270},
    		{name:'福建',value:535756},
    		{name:'江西',value:536241},
    		{name:'山东',value:537358},
    		{name:'河南',value:535961},
    		{name:'湖北',value:537054},
    		{name:'湖南',value:536568},
    		{name:'广东',value:463275},
    		{name:'广西',value:536265},
    		{name:'海南',value:180063},
    		{name:'重庆',value:536305},
    		{name:'四川',value:535961},
    		{name:'贵州',value:536158},
    		{name:'云南',value:536208},
    		{name:'西藏',value:532553},
    		{name:'陕西',value:536273},
    		{name:'甘肃',value:536158},
    		{name:'青海',value:669194},
    		{name:'宁夏',value:665650},
    		{name:'新疆',value:844360},
    	];
    	option = getOptionMap(mapData,n);
    }else if(n =="IP地址"){
    	mapData = [
    		{name:'北京',value:217304},
    		{name:'天津',value:203977},
    		{name:'河北',value:216226},
    		{name:'山西',value:206788},
    		{name:'内蒙古',value:195609},
    		{name:'辽宁',value:209396},
    		{name:'吉林',value:204097},
    		{name:'黑龙江',value:196673},
    		{name:'上海',value:200727},
    		{name:'江苏',value:227270},
    		{name:'浙江',value:237894},
    		{name:'安徽',value:195113},
    		{name:'福建',value:215453},
    		{name:'江西',value:200030},
    		{name:'山东',value:208377},
    		{name:'河南',value:205239},
    		{name:'湖北',value:208592},
    		{name:'湖南',value:207054},
    		{name:'广东',value:226310},
    		{name:'广西',value:196506},
    		{name:'海南',value:192122},
    		{name:'重庆',value:202875},
    		{name:'四川',value:206217},
    		{name:'贵州',value:194226},
    		{name:'云南',value:197383},
    		{name:'西藏',value:191706},
    		{name:'陕西',value:207322},
    		{name:'甘肃',value:195824},
    		{name:'青海',value:191954},
    		{name:'宁夏',value:191714},
    		{name:'新疆',value:193954},
    	];
    	option = getOptionMap(mapData,n);
    }
    mapChart.setOption(option);
})

window.addEventListener("resize", function () {
    mapChart.resize();
});
